package com.weibo.report.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.weibo.common.CommonUtil;
import com.weibo.common.ValidateUserServlet;
import com.weibo.report.Report;
import com.weibo.report.service.ReportService;
import com.weibo.report.service.imp.ReportServiceImp;
import com.weibo.sql.CommonParm;
import com.weibo.user.User;

public class ReportServlet extends ValidateUserServlet {
	private static final Logger logger = Logger.getLogger(ReportServlet.class);
	private ReportService reportService = new ReportServiceImp();
	@Override 
	public void doService(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		Object host_id = request.getParameter("host_id");
		Object rep_content = request.getParameter("rep_content");
		if(host_id!=null&&rep_content!=null){
			User current_user = CommonUtil.getLoginUser(request);
			try {
				request.setCharacterEncoding("UTF-8");
				response.setCharacterEncoding("UTF-8");
				PrintWriter out = response.getWriter();
				if (current_user != null) {
					Report report = new Report();
					report.setHost_id((String)host_id);
					report.setUser_id(current_user.getUser_id());
					report.setRep_reson((String)rep_content);
					out.print(reportService.addReport(report));
				}else{
					out.print(CommonParm.LOGIN_TIMEOUT);
				}
				out.close();
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			// response.setContentType("text/html;charset=UTF-8");
			catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}

}
